package com.ruoyi.spspublic.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.spspublic.domain.TMisSign;
import com.ruoyi.spspublic.service.ITMisSignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.ruoyi.common.utils.uuid.IdUtils.simpleUUID;

/**
 * 签字信息Controller
 *
 * @author wangwei
 * @date 2023-06-23
 */
@RestController
@RequestMapping("/spspublic/sign")
public class TMisSignController extends BaseController {
  @Autowired private ITMisSignService tMisSignService;

  /** 查询签字信息列表 */
  //    @PreAuthorize("@ss.hasPermi('spspublic:sign:list')")
  @GetMapping("/list")
  public TableDataInfo list(TMisSign tMisSign) {
    startPage();
    List<TMisSign> list = tMisSignService.selectTMisSignList(tMisSign);
    return getDataTable(list);
  }

  /** 导出签字信息列表 */
  @PreAuthorize("@ss.hasPermi('spspublic:sign:export')")
  @Log(title = "签字信息", businessType = BusinessType.EXPORT)
  @GetMapping("/export")
  public AjaxResult export(TMisSign tMisSign) {
    List<TMisSign> list = tMisSignService.selectTMisSignList(tMisSign);
    ExcelUtil<TMisSign> util = new ExcelUtil<TMisSign>(TMisSign.class);
    return util.exportExcel(list, "sign");
  }

  /** 获取签字信息详细信息 */
  //    @PreAuthorize("@ss.hasPermi('spspublic:sign:query')")
  @GetMapping(value = "/{ctId}")
  public AjaxResult getInfo(@PathVariable("ctId") String ctId) {
    return AjaxResult.success(tMisSignService.selectTMisSignById(ctId));
  }

  /** 新增签字信息 */
  @PreAuthorize("@ss.hasPermi('spspublic:sign:add')")
  @Log(title = "签字信息", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@RequestBody TMisSign tMisSign) {
    // 设置唯一id
    tMisSign.setCtId(simpleUUID());
    int row = tMisSignService.insertTMisSign(tMisSign);
    if (row > 0) {
      // 设置发送通知（同级进行通知，目前还不考虑），理论上应该作为事务一起提交，否则导致数据可能写入失败。
    }
    return toAjax(row);
  }

  /** 修改签字信息 */
  @PreAuthorize("@ss.hasPermi('spspublic:sign:edit')")
  @Log(title = "签字信息", businessType = BusinessType.UPDATE)
  @PostMapping("/edit")
  public AjaxResult edit(@RequestBody TMisSign tMisSign) {
    return toAjax(tMisSignService.updateTMisSign(tMisSign));
  }

  /** 删除签字信息 */
  @PreAuthorize("@ss.hasPermi('spspublic:sign:remove')")
  @Log(title = "签字信息", businessType = BusinessType.DELETE)
  @PostMapping("/delete/{ctIds}")
  public AjaxResult remove(@PathVariable String[] ctIds) {
    return toAjax(tMisSignService.deleteTMisSignByIds(ctIds));
  }

  /*@PostMapping(value = "/batchSign")
  //@Log(businessType = BusinessType.BATCH, genericModule = true)
  public AjaxResult batchSign(@RequestBody BatchSignDto batchSignDto) {
    return tMisSignService.batchSign(batchSignDto);
  }*/
}
